﻿Public Class DRUGITEM
    Dim connect As CONDB = CONDB.NewConnection()
    Dim PROVIDER_Check As New PROVIDERSCLASS
    
    Private Sub DRUGITEM_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(dacccode AS CHAR(4)) AS DACCODE, daccname FROM masdrgacc WHERE status = '" & 1 & "'"
        s = New FILTERCLASS(DACCCODETxt, sql, "รหัสบัญชียา,ชื่อบัญชียา", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s.SetShowBorder = True

        Dim s2 As FILTERCLASS
        Dim sql2 As String = "SELECT CAST(gdcode AS CHAR(4)) AS GDCODE, grpdrg FROM masgrpdrg WHERE status = '" & 1 & "'"
        s2 = New FILTERCLASS(GDCODETxt, sql2, "รหัสกลุ่มยา,ชื่อกลุ่มยา", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s2.SetShowBorder = True

        Dim s3 As FILTERCLASS
        Dim sql3 As String = "SELECT CAST(dgtyid AS CHAR(4)) AS DGTYID, drgtype FROM masdrgtype WHERE status = '" & 1 & "'"
        s3 = New FILTERCLASS(DGTYIDTxt, sql3, "รหัสประเภทยา,ชื่อประเภทยา", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s3.SetShowBorder = True

        Dim s4 As FILTERCLASS
        Dim sql4 As String = "SELECT CAST(dform AS CHAR(4)) AS DFORM, dosageform as b FROM masdrgdosage WHERE status = '" & 1 & "'"
        s4 = New FILTERCLASS(DFORMTxt, sql4, "รหัสประเภทยา,ชื่อประเภทยา", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s4.SetShowBorder = True

        Dim s5 As FILTERCLASS
        Dim sql5 As String = "SELECT CAST(inten AS CHAR(4)) AS INTEN, intensity FROM masdrginten WHERE status = '" & 1 & "'"
        s5 = New FILTERCLASS(INTENTxt, sql5, "รหัสความรุนแรงของยา,ความรุนแรงของยา", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s5.SetShowBorder = True

        Dim s6 As FILTERCLASS
        Dim sql6 As String = "SELECT CAST(drgmid AS CHAR(4)) AS DRGMID, makername FROM masdrgmaker WHERE status = '" & 1 & "'"
        s6 = New FILTERCLASS(DRGMIDTxt, sql6, "รหัสผู้ผลิตยา,ผู้ผลิตยา", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s6.SetShowBorder = True

        Dim s7 As FILTERCLASS
        Dim sql7 As String = "SELECT CAST(keepid AS CHAR(4)) AS KEEPID, dkeepname as b FROM masdrgkeep WHERE status = '" & 1 & "'"
        s7 = New FILTERCLASS(KEEPIDTxt, sql7, "รหัสการเก็บยา,การเก็บยา", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s7.SetShowBorder = True

        Dim s8 As FILTERCLASS
        Dim sql8 As String = "SELECT CAST(location AS CHAR(4)) AS LOCATION, locatename FROM maslocationd WHERE status = '" & 1 & "'"
        s8 = New FILTERCLASS(LOCATIONTxt, sql8, "รหัสสถานที่เก็บยา,สถานที่เก็บยา", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s8.SetShowBorder = True

        Dim s9 As FILTERCLASS
        Dim sql9 As String = "SELECT CAST(unitid AS CHAR(4)) AS UNITID, unitname_th, unitname_en, f_lab, f_xry FROM masunit WHERE status = '" & 1 & "'"
        s9 = New FILTERCLASS(B_UNITTxt, sql9, "รหัสหน่วยซื้อขาย,หน่วยซื้อขาย(ไทย),หน่วยซื้อขาย(อังกฤษ),หน่วย(แล็บ),หน่วย(x-ray)", "80,100,120,80,80", "1,1,1,1,1", "1,1,1,0,0")
        's.SetShowInDown = False
        s9.SetShowBorder = True

        Dim s10 As FILTERCLASS
        Dim sql10 As String = "SELECT CAST(UNITID AS CHAR(4)) AS UNITID, UNITNAME_TH, UNITNAME_EN, F_LAB, F_XRY FROM masunit WHERE STATUS = '" & 1 & "'"
        s10 = New FILTERCLASS(S_UNITTxt, sql10, "รหัสหน่วยซื้อขาย,หน่วยซื้อขาย(ไทย),หน่วยซื้อขาย(อังกฤษ),หน่วย(แล็บ),หน่วย(x-ray)", "80,100,120,80,80", "1,1,1,1,1", "1,1,1,0,0")
        's.SetShowInDown = False
        s10.SetShowBorder = True

        Dim s11 As FILTERCLASS
        Dim sql11 As String = "SELECT CAST(atcl1code AS CHAR(2)) AS ATCL1CODE, al1name FROM masdrgatcl1"
        s11 = New FILTERCLASS(ATCL1CODETxt, sql11, "รหัสออกฤทธิ์,การออกฤทธิ์", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s11.SetShowBorder = True

        Dim s12 As FILTERCLASS
        Dim sql12 As String = "SELECT CAST(unitid AS CHAR(4)) AS UNITID, unitname_th, unitname_en, f_lab, f_xry FROM masunit WHERE status = '" & 1 & "' AND f_time <> '1'"
        s12 = New FILTERCLASS(U_UNITTxt, sql12, "รหัสหน่วยซื้อขาย,หน่วยซื้อขาย(ไทย),หน่วยซื้อขาย(อังกฤษ),หน่วย(แล็บ),หน่วย(x-ray)", "80,100,120,80,80", "1,1,1,1,1", "1,1,1,0,0")
        's.SetShowInDown = False
        s12.SetShowBorder = True

        Dim s13 As FILTERCLASS
        Dim sql13 As String = "SELECT CAST(ugid AS CHAR(4)) AS UGID, ugname, ugname_en, f_food FROM masdrgug WHERE status = '" & 1 & "'"
        s13 = New FILTERCLASS(UGIDTxt, sql13, "รหัสการใช้ยา,การใช้ยา(ไทย),การใช้ยา(อังกฤษ),รับประทาน", "80,100,120,80", "1,1,1,1", "1,1,1,0")
        's.SetShowInDown = False
        s13.SetShowBorder = True

        'Dim s10 As FILTERCLASS
        'Dim sql7 As String = "SELECT CAST(KEEPID AS CHAR(4)) AS KEEPID, DKEEPNAME as b FROM masdrgkeep WHERE STATUS = '" & 1 & "'"
        's7 = New FILTERCLASS(KEEPIDTxt, sql7, "รหัสการเก็บยา,การเก็บยา", "80,200", "1,1", "1,1")
        ''s.SetShowInDown = False
        's7.SetShowBorder = True

        

        queryGridDrugitem()

        DesignForm(Me)
        DesignGrid(DRUGITEMGrid)

        rdbF_msDrug.Checked = True

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Public Sub queryGridDrugitem()
        Dim objSelectDataMasdrugitem As New drugItemClass
        Dim drugitemData As DataTable
        drugitemData = connect.GetTable(objSelectDataMasdrugitem.selectDrugitem_)
        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
        DRUGITEMGrid.PrimaryGrid.DataSource = drugitemData
    End Sub

    Public Sub clearFormDrugitem()
        DRGCODETxt.Text = ""
        PRDCODETxt.Text = ""
        PRDCODETxt.Visible = False
        Label30.Visible = False
        DACCCODETxt.Text = ""
        DRGLISTChk.Checked = False
        GDCODETxt.Text = ""
        GENERICNAMETxt.Text = ""
        TRADENAMETxt.Text = ""
        DGTYIDTxt.Text = ""
        DFORMTxt.Text = ""
        INTENTxt.Text = ""
        UGIDTxt.Text = ""
        REMARKTxt.Text = ""
        DRGMIDTxt.Text = ""
        KWORDTxt.Text = ""
        MAXLVTxt.Text = ""
        MINLVTxt.Text = ""
        REORDERTxt.Text = ""
        AVGUSETxt.Text = ""
        KEEPIDTxt.Text = ""
        LOCATIONTxt.Text = ""
        B_UNITTxt.Text = ""
        S_UNITTxt.Text = ""
        U_UNITTxt.Text = ""
        ATCL1CODETxt.Text = ""
        ATCL2CODETxt.Text = ""
        ATCL3CODETxt.Text = ""
        ATCL4CODETxt.Text = ""
        ATCL5CODETxt.Text = ""
        ATCTxt.Text = ""
        DrugitemStatusChk.Checked = False
        linePrdcode.Visible = False
        lblPrdcode.Visible = False
    End Sub

    Private Sub DACCCODETxt_Click(sender As Object, e As EventArgs) Handles DACCCODETxt.Click
        DACCCODETxt.Text = ""
    End Sub

    Private Sub GDCODETxt_Click(sender As Object, e As EventArgs) Handles GDCODETxt.Click
        GDCODETxt.Text = ""
    End Sub

    Private Sub DGTYIDTxt_Click(sender As Object, e As EventArgs) Handles DGTYIDTxt.Click
        DGTYIDTxt.Text = ""
    End Sub

    Private Sub DFORMTxt_Click(sender As Object, e As EventArgs) Handles DFORMTxt.Click
        DFORMTxt.Text = ""
    End Sub

    Private Sub INTENTxt_Click(sender As Object, e As EventArgs) Handles INTENTxt.Click
        INTENTxt.Text = ""
    End Sub

    Private Sub DRGMIDTxt_Click(sender As Object, e As EventArgs) Handles DRGMIDTxt.Click
        DRGMIDTxt.Text = ""
    End Sub

    Private Sub KEEPIDTxt_Click(sender As Object, e As EventArgs) Handles KEEPIDTxt.Click
        KEEPIDTxt.Text = ""
    End Sub

    Private Sub LOCATIONTxt_Click(sender As Object, e As EventArgs) Handles LOCATIONTxt.Click
        LOCATIONTxt.Text = ""
    End Sub

    Private Sub B_UNITTxt_Click(sender As Object, e As EventArgs) Handles B_UNITTxt.Click
        B_UNITTxt.Text = ""
    End Sub

    Private Sub S_UNITTxt_Click(sender As Object, e As EventArgs) Handles S_UNITTxt.Click
        S_UNITTxt.Text = ""
    End Sub

    Private Sub ATCL1CODETxt_Click(sender As Object, e As EventArgs) Handles ATCL1CODETxt.Click
        ATCL1CODETxt.Text = ""
    End Sub

    Private Sub ATCL1CODETxt_TextChanged(sender As Object, e As EventArgs) Handles ATCL1CODETxt.TextChanged
        queryATCL2()
    End Sub

    Public Sub queryATCL2()
        Dim s12 As FILTERCLASS
        Dim sql12 As String = "SELECT CAST(b.`atcl2code` as CHAR(2)) AS ATCL2CODE, b.`al2name` as 'ประเภทการออกฤทธิ์' FROM masdrgatcl2 b JOIN masdrgatcl1 a ON b.atcl1code = a.atcl1code WHERE b.atcl1code = '" & ATCL1CODETxt.Tag & "'"
        s12 = New FILTERCLASS(ATCL2CODETxt, sql12, "รหัสออกฤทธิ์,การออกฤทธิ์", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s12.SetShowBorder = True
    End Sub

    Private Sub ATCL2CODETxt_Click(sender As Object, e As EventArgs) Handles ATCL2CODETxt.Click
        ATCL2CODETxt.Text = ""
    End Sub

    Private Sub ATCL2CODETxt_TextChanged(sender As Object, e As EventArgs) Handles ATCL2CODETxt.TextChanged
        queryATCL3()
    End Sub

    Public Sub queryATCL3()
        Dim s13 As FILTERCLASS
        Dim sql13 As String = "SELECT CAST(c.atcl3code AS CHAR(2)) AS ATCL3CODE, c.al3name as 'ประเภทการออกฤทธิ์' FROM masdrgatcl3 c JOIN masdrgatcl2 b ON b.atcl2code = c.atcl2code JOIN masdrgatcl1 a ON a.atcl1code = b.atcl1code WHERE c.atcl2code = '" & ATCL2CODETxt.Tag & "'"
        s13 = New FILTERCLASS(ATCL3CODETxt, sql13, "รหัสออกฤทธิ์,การออกฤทธิ์", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s13.SetShowBorder = True
    End Sub

    Private Sub ATCL3CODETxt_Click(sender As Object, e As EventArgs) Handles ATCL3CODETxt.Click
        ATCL3CODETxt.Text = ""
    End Sub

    Private Sub ATCL3CODETxt_TextChanged(sender As Object, e As EventArgs) Handles ATCL3CODETxt.TextChanged
        queryATCL4()
    End Sub

    Public Sub queryATCL4()
        Dim s14 As FILTERCLASS
        Dim sql14 As String = "SELECT CAST(d.atcl4code AS CHAR(2)) AS ATCL4CODE, d.al4name as 'ประเภทการออกฤทธิ์' FROM masdrgatcl4 d JOIN masdrgatcl3 c ON d.atcl3code = c.atcl3code JOIN masdrgatcl2 b ON c.atcl2code = b.atcl2code JOIN masdrgatcl1 a ON b.atcl1code = a.atcl1code WHERE d.atcl3code = '" & ATCL3CODETxt.Tag & "'"
        s14 = New FILTERCLASS(ATCL4CODETxt, sql14, "รหัสออกฤทธิ์,การออกฤทธิ์", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s14.SetShowBorder = True
    End Sub

    Private Sub ATCL4CODETxt_Click(sender As Object, e As EventArgs) Handles ATCL4CODETxt.Click
        ATCL4CODETxt.Text = ""
    End Sub

    Private Sub ATCL4CODETxt_TextChanged(sender As Object, e As EventArgs) Handles ATCL4CODETxt.TextChanged
        queryATCL5()
    End Sub

    Public Sub queryATCL5()
        Dim s15 As FILTERCLASS
        Dim sql15 As String = "SELECT CAST(e.atcl5code AS CHAR(2)) AS ATCL5CODE, e.al5name as 'ประเภทการออกฤทธิ์' FROM masdrgatcl5 e JOIN masdrgatcl4 d ON e.atcl4code = d.atcl4code JOIN masdrgatcl3 c ON d.atcl3code = c.atcl3code JOIN masdrgatcl2 b ON c.atcl2code = b.atcl2code JOIN masdrgatcl1 a ON b.atcl1code = a.atcl1code WHERE e.atcl4code = '" & ATCL4CODETxt.Tag & "'"
        s15 = New FILTERCLASS(ATCL5CODETxt, sql15, "รหัสออกฤทธิ์,การออกฤทธิ์", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s15.SetShowBorder = True
    End Sub

    Private Sub ATCL5CODETxt_Click(sender As Object, e As EventArgs) Handles ATCL5CODETxt.Click
        ATCL5CODETxt.Text = ""
    End Sub

    Private Sub ATCL5CODETxt_TextChanged(sender As Object, e As EventArgs) Handles ATCL5CODETxt.TextChanged
        ATCTxt.Text = ATCL1CODETxt.Tag & ATCL2CODETxt.Tag & ATCL3CODETxt.Tag & ATCL4CODETxt.Tag & ATCL5CODETxt.Tag
    End Sub

    Private Sub DRUGITEMGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles DRUGITEMGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        'f.TXT_CID.Text = grid.Cells.Item(2).Value

        DRGCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสยา").Value()
        PRDCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสผลิตภัณฑ์").Value()

        Try
            DACCCODETxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสบัญชียา").Value()
            DACCCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("บัญชียา").Value()
        Catch ex As Exception
            DACCCODETxt.Tag = ""
            DACCCODETxt.Text = ""
        End Try

        Try
            GDCODETxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("กลุ่มยา").Value()
            GDCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อกลุ่มยา").Value()
        Catch ex As Exception
            GDCODETxt.Tag = ""
            GDCODETxt.Text = ""
        End Try

        Try
            ATCL1CODETxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัส class ยา 1").Value()
            ATCL1CODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("class ยา 1").Value()
        Catch ex As Exception
            ATCL1CODETxt.Tag = ""
            ATCL1CODETxt.Text = ""
        End Try

        Try
            ATCL2CODETxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัส class ยา 2").Value()
            ATCL2CODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("class ยา 2").Value()
        Catch ex As Exception
            ATCL2CODETxt.Tag = ""
            ATCL2CODETxt.Text = ""
        End Try

        Try
            ATCL3CODETxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัส class ยา 3").Value()
            ATCL3CODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("class ยา 3").Value()
        Catch ex As Exception
            ATCL3CODETxt.Tag = ""
            ATCL3CODETxt.Text = ""
        End Try

        Try
            ATCL4CODETxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัส class ยา 4").Value()
            ATCL4CODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("class ยา 4").Value()
        Catch ex As Exception
            ATCL4CODETxt.Tag = ""
            ATCL4CODETxt.Text = ""
        End Try

        Try
            ATCL5CODETxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัส class ยา 5").Value()
            ATCL5CODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("class ยา 5").Value()
        Catch ex As Exception
            ATCL5CODETxt.Tag = ""
            ATCL5CODETxt.Text = ""
        End Try

        ATCTxt.Text = ATCL1CODETxt.Tag & ATCL2CODETxt.Tag & ATCL3CODETxt.Tag & ATCL4CODETxt.Tag & ATCL5CODETxt.Tag
        'editATCTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัส class ยา ATC").Value()

        Try
            DFORMTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสรูปแบบยา").Value()
            DFORMTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รูปแบบยา").Value()
        Catch ex As Exception
            DFORMTxt.Tag = ""
            DFORMTxt.Text = ""
        End Try

        Try
            DGTYIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสประเภทยา").Value()
            DGTYIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ประเภทยา").Value()
        Catch ex As Exception
            DGTYIDTxt.Tag = ""
            DGTYIDTxt.Text = ""
        End Try

        Try
            INTENTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสความรุนแรง").Value()
            INTENTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ความรุนแรง").Value()
        Catch ex As Exception
            INTENTxt.Tag = ""
            INTENTxt.Text = ""
        End Try

        Try
            DRGMIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสผู้ผลิต").Value()
            DRGMIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ผู้ผลิต").Value()
        Catch ex As Exception
            DRGMIDTxt.Tag = ""
            DRGMIDTxt.Text = ""
        End Try

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("บัญชียาหลัก").Value() = True Then
            DRGLISTChk.Checked = True
        Else
            DRGLISTChk.Checked = False
        End If

        Try
            GENERICNAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อสามัญทางยา").Value()
        Catch ex As Exception
            GENERICNAMETxt.Text = ""
        End Try

        Try
            TRADENAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อทางการค้า").Value()
        Catch ex As Exception
            TRADENAMETxt.Text = ""
        End Try

        Try
            UGIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสการใช้ยา").Value()
            UGIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("การใช้ยา").Value()
        Catch ex As Exception
            UGIDTxt.Text = ""
        End Try

        Try
            REMARKTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หมายเหตุ").Value()
        Catch ex As Exception
            REMARKTxt.Text = ""
        End Try

        Try
            KEEPIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วิธีการเก็บ").Value()
        Catch ex As Exception
            KEEPIDTxt.Tag = ""
        End Try

        Try
            LOCATIONTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานที่เก็บยา").Value()
        Catch ex As Exception
            LOCATIONTxt.Tag = ""
        End Try

        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ปริมาณสูงสุด").Value IsNot Nothing And CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ปริมาณสูงสุด").Value() IsNot DBNull.Value And CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ปริมาณสูงสุด").Value().ToString <> "" Then
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ปริมาณสูงสุด").Value() IsNot DBNull.Value Then
            MAXLVTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ปริมาณสูงสุด").Value()
        Else
            MAXLVTxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ปริมาณต่ำสุด").Value() IsNot DBNull.Value Then
            MINLVTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ปริมาณต่ำสุด").Value()
        Else
            MINLVTxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("อัตราเฉลี่ยการใช้").Value() IsNot DBNull.Value Then
            AVGUSETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("อัตราเฉลี่ยการใช้").Value()
        Else
            AVGUSETxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ปริมาณถึงจุดสั่งซื้อ").Value() IsNot DBNull.Value Then
            REORDERTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ปริมาณถึงจุดสั่งซื้อ").Value()
        Else
            REORDERTxt.Text = ""
        End If

        Try
            KWORDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("คำค้นหา").Value()
        Catch ex As Exception
            KWORDTxt.Text = ""
        End Try

        Try
            KEEPIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วิธีการเก็บ").Value()
            KEEPIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อวิธีการเก็บ").Value()
        Catch ex As Exception
            KEEPIDTxt.Tag = ""
            KEEPIDTxt.Text = ""
        End Try

        Try
            LOCATIONTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานที่เก็บยา").Value()
            LOCATIONTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อสถานที่เก็บยา").Value()
        Catch ex As Exception
            LOCATIONTxt.Tag = ""
            LOCATIONTxt.Text = ""
        End Try

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยซื้อ").Value() IsNot DBNull.Value Then
            B_UNITTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยซื้อ").Value()
            B_UNITTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหน่วยซื้อ").Value()
        Else
            B_UNITTxt.Tag = ""
            B_UNITTxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยขาย").Value() IsNot DBNull.Value Then
            S_UNITTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยขาย").Value()
            S_UNITTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหน่วยขาย").Value()
        Else
            S_UNITTxt.Tag = ""
            S_UNITTxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยใช้").Value() IsNot DBNull.Value Then
            U_UNITTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยใช้").Value()
            U_UNITTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหน่วยใช้").Value()
        Else
            U_UNITTxt.Tag = ""
            U_UNITTxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสประเภทเวชภัณฑ์").Value() IsNot DBNull.Value Then
            If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสประเภทเวชภัณฑ์").Value() = True Then
                rdbF_msDrug.Checked = False
                rdbF_msMedic.Checked = True
            Else
                rdbF_msDrug.Checked = True
                rdbF_msMedic.Checked = False
            End If
        Else
            rdbF_msDrug.Checked = False
            rdbF_msMedic.Checked = False
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            DrugitemStatusChk.Checked = True
        Else
            DrugitemStatusChk.Checked = False
        End If

        Dim objChkboxUpdate As New CLICKGRIDCHECKBOX
        objChkboxUpdate.clickChkboxUpdate("drugitem", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value(), "STATUS", "DRGCODE", DRGCODETxt.Text)

        'DRGCODETxt.Enabled = False
        Label30.Visible = True
        PRDCODETxt.Visible = True
        linePrdcode.Visible = True
        lblPrdcode.Visible = True

        addDrugItem.Enabled = False
    End Sub

    Private Sub addDrugItem_Click(sender As Object, e As EventArgs) Handles addDrugItem.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If DRGCODETxt.Text.ToString.Length > 0 And GENERICNAMETxt.Text.ToString.Length > 0 And DFORMTxt.Text.ToString.Length > 0 And B_UNITTxt.Text.ToString.Length > 0 And S_UNITTxt.Text.ToString.Length > 0 Then

                    Dim objInsertData As New drugItemClass
                    objInsertData.DRGCODE_ = DRGCODETxt.Text
                    objInsertData.GDCODE_ = GDCODETxt.Tag
                    objInsertData.DACCCODE_ = DACCCODETxt.Tag
                    objInsertData.ATCL1CODE_ = ATCL1CODETxt.Tag
                    objInsertData.ATCL2CODE_ = ATCL2CODETxt.Tag
                    objInsertData.ATCL3CODE_ = ATCL3CODETxt.Tag
                    objInsertData.ATCL4CODE_ = ATCL4CODETxt.Tag
                    objInsertData.ATCL5CODE_ = ATCL5CODETxt.Tag
                    objInsertData.ATC_ = ATCTxt.Text
                    objInsertData.DFORM_ = DFORMTxt.Tag
                    objInsertData.DGTYID_ = DGTYIDTxt.Tag
                    objInsertData.INTEN_ = INTENTxt.Tag

                    If UGIDTxt.Text.Length.ToString > 0 Then
                        objInsertData.UGID_ = UGIDTxt.Tag
                    Else
                        objInsertData.UGID_ = Nothing
                    End If

                    objInsertData.UGID_ = UGIDTxt.Tag
                    objInsertData.DRGMID_ = DRGMIDTxt.Tag
                    objInsertData.DRGLIST_ = DRGLISTChk.Checked
                    objInsertData.GENERICNAME_ = GENERICNAMETxt.Text
                    objInsertData.TRADENAME_ = TRADENAMETxt.Text
                    objInsertData.DLABEL_ = UGIDTxt.Text
                    objInsertData.REMARK_ = REMARKTxt.Text
                    objInsertData.KEEPID_ = KEEPIDTxt.Tag
                    objInsertData.LOCATION_ = LOCATIONTxt.Tag

                    If MAXLVTxt.Text.ToString.Length > 0 Then
                        objInsertData.MAXLV_ = CDbl(MAXLVTxt.Text)
                    End If

                    If MINLVTxt.Text.ToString.Length > 0 Then
                        objInsertData.MINLV_ = CDbl(MINLVTxt.Text)
                    End If

                    If AVGUSETxt.Text.ToString.Length > 0 Then
                        objInsertData.AVGUSE_ = CDbl(AVGUSETxt.Text)
                    End If

                    If REORDERTxt.Text.ToString.Length > 0 Then
                        objInsertData.REORDER_ = CDbl(REORDERTxt.Text)
                    End If

                    objInsertData.STATUS_ = DrugitemStatusChk.Checked
                    objInsertData.KWORD_ = KWORDTxt.Text

                    objInsertData.B_UNIT_ = B_UNITTxt.Tag
                    objInsertData.S_UNIT_ = S_UNITTxt.Tag
                    objInsertData.U_UNIT_ = U_UNITTxt.Tag

                    If rdbF_msDrug.Checked = True Then
                        objInsertData.F_MS_ = 0
                    End If

                    If rdbF_msMedic.Checked = True Then
                        objInsertData.F_MS_ = 1
                    End If

                    If rdbF_msDrug.Checked = False And rdbF_msMedic.Checked = False Then
                        objInsertData.F_MS_ = "null"
                    End If

                    If objInsertData.addDrugitem() = True Then
                        queryGridDrugitem()
                        clearFormDrugitem()
                        addDrugItem.Enabled = True
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูล รหัสยา, ชื่อสามัญทางยา, รูปแบบบรรจุ, หน่วยซื้อ, หน่วยขาย ให้ครบถ้วนก่อนทำการบันทึกข้อมูล")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editDrugItem_Click(sender As Object, e As EventArgs) Handles editDrugItem.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If DRGCODETxt.Text.ToString.Length > 0 And GENERICNAMETxt.Text.ToString.Length > 0 And DFORMTxt.Text.ToString.Length > 0 And B_UNITTxt.Text.ToString.Length > 0 And S_UNITTxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลยาดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New drugItemClass
                        objEditData.DRGCODE_ = DRGCODETxt.Text
                        objEditData.PRDCODE_ = PRDCODETxt.Text
                        objEditData.GDCODE_ = GDCODETxt.Tag
                        objEditData.DACCCODE_ = DACCCODETxt.Tag
                        objEditData.ATCL1CODE_ = ATCL1CODETxt.Tag
                        objEditData.ATCL2CODE_ = ATCL2CODETxt.Tag
                        objEditData.ATCL3CODE_ = ATCL3CODETxt.Tag
                        objEditData.ATCL4CODE_ = ATCL4CODETxt.Tag
                        objEditData.ATCL5CODE_ = ATCL5CODETxt.Tag
                        objEditData.ATC_ = ATCTxt.Text
                        objEditData.DFORM_ = DFORMTxt.Tag
                        objEditData.DGTYID_ = DGTYIDTxt.Tag

                        If INTENTxt.Text.Length.ToString > 0 Then
                            objEditData.INTEN_ = INTENTxt.Tag
                        Else
                            objEditData.INTEN_ = 0
                        End If

                        If UGIDTxt.Text.Length.ToString > 0 Then
                            objEditData.UGID_ = UGIDTxt.Tag
                        Else
                            objEditData.UGID_ = Nothing
                        End If

                        If DRGMIDTxt.Text.Length.ToString > 0 Then
                            objEditData.DRGMID_ = DRGMIDTxt.Tag
                        Else
                            objEditData.DRGMID_ = 0
                        End If

                        objEditData.DRGLIST_ = DRGLISTChk.Checked
                        objEditData.GENERICNAME_ = GENERICNAMETxt.Text
                        objEditData.TRADENAME_ = TRADENAMETxt.Text
                        objEditData.DLABEL_ = UGIDTxt.Text
                        objEditData.REMARK_ = REMARKTxt.Text

                        If KEEPIDTxt.Text.Length.ToString > 0 Then
                            objEditData.KEEPID_ = KEEPIDTxt.Tag
                        Else
                            objEditData.KEEPID_ = 0
                        End If

                        If LOCATIONTxt.Text.Length.ToString > 0 Then
                            objEditData.LOCATION_ = LOCATIONTxt.Tag
                        Else
                            objEditData.LOCATION_ = 0
                        End If

                        If MAXLVTxt.Text.ToString.Length > 0 Then
                            objEditData.MAXLV_ = CDbl(MAXLVTxt.Text)
                        End If

                        If MINLVTxt.Text.ToString.Length > 0 Then
                            objEditData.MINLV_ = CDbl(MINLVTxt.Text)
                        End If

                        If AVGUSETxt.Text.ToString.Length > 0 Then
                            objEditData.AVGUSE_ = CDbl(AVGUSETxt.Text)
                        End If

                        If REORDERTxt.Text.ToString.Length > 0 Then
                            objEditData.REORDER_ = CDbl(REORDERTxt.Text)
                        End If

                        objEditData.STATUS_ = DrugitemStatusChk.Checked
                        objEditData.KWORD_ = KWORDTxt.Text

                        objEditData.B_UNIT_ = B_UNITTxt.Tag
                        objEditData.S_UNIT_ = S_UNITTxt.Tag

                        If U_UNITTxt.Text.Length.ToString > 0 Then
                            objEditData.U_UNIT_ = U_UNITTxt.Tag
                        Else
                            objEditData.U_UNIT_ = 0
                        End If

                        If rdbF_msDrug.Checked = True Then
                            objEditData.F_MS_ = "0"
                        End If

                        If rdbF_msMedic.Checked = True Then
                            objEditData.F_MS_ = "1"
                        End If

                        If rdbF_msDrug.Checked = False And rdbF_msMedic.Checked = False Then
                            objEditData.F_MS_ = "null"
                        End If

                        If objEditData.editDrugitem() = True Then
                            queryGridDrugitem()
                            clearFormDrugitem()
                            addDrugItem.Enabled = True
                        End If
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูล รหัสยา, ชื่อสามัญทางยา, รูปแบบบรรจุ, หน่วยซื้อ, หน่วยขาย ให้ครบถ้วนก่อนทำการแก้ไขข้อมูล")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs)
        Dim nextform As New IMPORTEXCEL("drugitem")
        nextform.ShowDialog()
    End Sub

    Private Sub ButtonItem1_Click(sender As Object, e As EventArgs)
        Dim nextform As New IMPORTEXCEL("drugitem")
        nextform.ShowDialog()
    End Sub

    Private Sub btnClearForm_Click(sender As Object, e As EventArgs) Handles btnClearForm.Click
        queryGridDrugitem()
        clearFormDrugitem()

        addDrugItem.Enabled = True
    End Sub
End Class